package thelperinator

//import javax.inject.Inject;
import org.hibernate.SessionFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations
import org.springframework.jdbc.core.namedparam.SqlParameterSource
import org.springframework.jdbc.support.GeneratedKeyHolder
import org.springframework.jdbc.support.KeyHolder
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

import javax.naming.NamingException
import javax.persistence.Persistence
import java.sql.Connection

/**
 * Created by rr146517 on 4/25/14.
 */

@Service
@Transactional
class OwnerService {
    //@Inject private SessionFactory sessionFactory;
    SessionFactory sessionFactory;
    @Autowired private NamedParameterJdbcOperations jdbcTemplate
    public static final String CREATE_SQL =
        "insert into owner (lname, fname) values (:lname, :fname";


    public void createOwner(Owner owner) {
        SqlParameterSource params = new MapSqlParameterSource()
        .addValue("lname", "payton")
        .addValue("fname", "ryan")
        KeyHolder kh = new GeneratedKeyHolder()
        jdbcTemplate.update(CREATE_SQL, params, kh)


        //getSession().save(owner)
    }

//    public List<Owner> getOwners() {
//        return sessionFactory
//        /*
//        return getSession()
//        .createQuery("from owner").list();
//        */
//    }

}
